import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { JqtSpreadLinkVO, JqtSpreadLinkForm, JqtSpreadLinkQuery } from '@/api/bus/jqtSpreadLink/types';

/**
 * 查询推广链接列表
 * @param query
 * @returns {*}
 */

export const listJqtSpreadLink = (query?: JqtSpreadLinkQuery): AxiosPromise<JqtSpreadLinkVO[]> => {
  return request({
    url: '/bus/jqtSpreadLink/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询推广链接详细
 * @param id
 */
export const getJqtSpreadLink = (id: string | number): AxiosPromise<JqtSpreadLinkVO> => {
  return request({
    url: '/bus/jqtSpreadLink/' + id,
    method: 'get'
  });
};

/**
 * 新增推广链接
 * @param data
 */
export const addJqtSpreadLink = (data: JqtSpreadLinkForm) => {
  return request({
    url: '/bus/jqtSpreadLink',
    method: 'post',
    data: data
  });
};

/**
 * 修改推广链接
 * @param data
 */
export const updateJqtSpreadLink = (data: JqtSpreadLinkForm) => {
  return request({
    url: '/bus/jqtSpreadLink',
    method: 'put',
    data: data
  });
};

/**
 * 删除推广链接
 * @param id
 */
export const delJqtSpreadLink = (id: string | number | Array<string | number>) => {
  return request({
    url: '/bus/jqtSpreadLink/' + id,
    method: 'delete'
  });
};

/**
 * 新增推广链接
 * @param data
 */
export const changeStatus = (id: number | string, status: string) => {
  const data = {
    id,
    status
  };
  return request({
    url: '/bus/jqtSpreadLink/changeStatus',
    method: 'put',
    data: data
  });
};

/**
 * 复制推广链接
 * @param id
 */
export const copyLink = (id: number | string) => {
  return request({
    url: '/bus/jqtSpreadLink/copyLink',
    method: 'put',
    data: {
       id
    }
  });
};

/**
 * 查询推广链接详细
 * @param spreadUrl
 */
export const getJqtSpreadLinkInfo = (spreadUrl: string): AxiosPromise<JqtSpreadLinkVO> => {
  return request({
    url: '/api/jqtSpreadLink/' + spreadUrl,
    method: 'get'
  });
};

/**
 * 随机生成访客码
 * @param spreadUrl
 */
export const generateToken = (): AxiosPromise<string> => {
  return request({
    url: '/api/jqtSpreadLink/generateToken',
    method: 'get'
  });
};
